package com.example.module_base_core.baseview;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;

import com.harisucici.jetpackbase.base.HBaseFragment;
import com.harisucici.jetpackbase.base.HBaseViewModel;

/**
 * @Author : 作者 马坤
 * @Time : On 2020/12/19 18:39
 * @Page: On com.example.module_base_core.baseview
 * @Description : BaseFragment
 */
public abstract class BaseFragment<V extends ViewDataBinding, VM extends HBaseViewModel> extends HBaseFragment<V, VM> implements View.OnClickListener {

    private static final int MIN_CLICK_DELAY_TIME = 1000;

    private static long lastClickTime;

    //设置布局
    public abstract int initCView(Bundle savedInstanceState);

    //绑定binding
    public abstract int initVM();

    //双击事件
    public abstract void onMultiClick(View v);

    /**
     * 绑定binding
     *
     * @return
     */
    @Override
    public int initVariableId() {
        return initVM();
    }

    /**
     * 设置布局(引用父类)
     *
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return initCView(savedInstanceState);
    }

    /**
     * 双击事件
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            lastClickTime = curClickTime;
            onMultiClick(v);
        }
    }
}
